﻿using System;
using System.Configuration;
using System.Web.Configuration;
using System.Web;
using System.Web.SessionState;

namespace VioletDevelopmentLaboratory.Net.Web.Configuration
{
	public sealed class SessionStateSectionManager : ConfigurationManagerBase
	{
		private SessionStateSection section;

		public SessionStateSectionManager()
		{
			this.section = (SessionStateSection)base.GetConfigurationSection("system.web/sessionState");
		}

		public void Modify(bool allowCustomSqlDatabase, HttpCookieMode cookieless, string cookieName, string customProvider, SessionStateMode mode, string partitionResolverType, bool regenerateExpiredSessionId, string sessionIDManagerType, TimeSpan sqlCommandTimeout, string sqlConnectionString, string StateConnectionString, TimeSpan stateNetworkTimeout, TimeSpan timeout, bool useHostingIdentity)
		{
			this.section.AllowCustomSqlDatabase = allowCustomSqlDatabase;
			this.section.Cookieless = cookieless;
			this.section.CookieName = cookieName;
			this.section.CustomProvider = customProvider;
			this.section.Mode = mode;
			this.section.PartitionResolverType = partitionResolverType;
			this.section.RegenerateExpiredSessionId = regenerateExpiredSessionId;
			this.section.SessionIDManagerType = sessionIDManagerType;
			this.section.SqlCommandTimeout = sqlCommandTimeout;
			this.section.SqlConnectionString = sqlConnectionString;
			this.section.StateConnectionString = StateConnectionString;
			this.section.StateNetworkTimeout = stateNetworkTimeout;
			this.section.Timeout = timeout;
			this.section.UseHostingIdentity = useHostingIdentity;
			this.Save();
		}
		public SessionStateSection GetSessionState()
		{
			return this.section;
		}




		public void AddProvider(string name, string type)
		{
			this.section.Providers.Add(new System.Configuration.ProviderSettings(name, type));
			this.Save();
		}
		public void ModifyProvider(string name, string type)
		{
			this.section.Providers[name].Type = type;
			this.Save();
		}
		public void RemoveProvider(string name)
		{
			this.section.Providers.Remove(name);
			this.Save();
		}
		public void ClearProviders()
		{
			this.section.Providers.Clear();

			this.Save();
		}
		public ProviderSettings GetProvider(string name)
		{
			return this.section.Providers[name];
		}
		public ProviderSettingsCollection GetProviders()
		{
			return this.section.Providers;
		}
	}
}